<?php
/*
 * variable-paie/index.phtml
 */
?>
<?php
$title = "Variable de Paie";
$this->headTitle($title);

// Variables
$site	 = $this->site;
$periode = $this->periode;
?>
<div class="content-head">
    <h3>
	<?php echo $title; ?> pour le site <a href='#' id="site" data-type="select"><?php echo $site->libelle; ?></a> pour la <a href="#" id="periode" data-type="select"><?php echo $periode->libelle; ?></a>
	<img src='<?php echo $this->basePath() . '/img/rhx/refresh-16x16.png' ?>' title="Actualiser la liste" class='rhx-refresh'>
    </h3>
</div>

<form id="variable-data" action="#" method="post">
    <input type="hidden" id="data-site" name="site" value="<?php echo $site->id; ?>">
    <input type="hidden" id="data-periode" name="periode" value="<?php echo $periode->id; ?>">
</form>

<div class="content-body">
    <!-- CONTENU -->
    <div id="content-data">
	<!-- AJAX LOADING -->
    </div>
</div>

<script type="text/javascript">
    // Démarrage
    $(function() {
	// Chargement de la variable de paie pour le site 1
	refresh();

	// Mise à jour
	$('.rhx-refresh').click(function(e) {
	    e.preventDefault();
	    return refresh();
	});

	// Site Editable
	$('#site').editable({
	    title: 'Liste des Sites',
	    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonSiteList')) ?>',
	    validate: function(value) {
		$('#data-site').val(value);
		refresh();
		changeSite(value);
	    }
	});

	// Periode Editable
	$('#periode').editable({
	    title: 'Liste des Périodes',
	    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'variable', 'action'	 => 'jsonPeriodeList')) ?>',
	    validate: function(value) {
		$('#data-periode').val(value);
		changePeriode(value);
		refresh();
	    }
	});
    });

    // Rafraichissement
    function refresh() {
	ajax = $.ajax({
	    type: 'post',
	    url: '<?php echo $this->url('RHX/default', array('controller'	 => 'variable', 'action'	 => 'load')) ?>',
	    data: $('#variable-data').serialize()
	});
	ajax.success(function(data) {
	    $('#content-data').hide().html(data).fadeIn('normal');
	});
	ajax.error(function() {
	    $('#content-data').hide().html("<div class='rh-error'>Contenu Impossible à charger</div>").fadeIn('normal');
	});

	return false;
    }
</script>